﻿using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using BLL;
using IFactory;

public partial class UserPlanWeek_UserWeekPlanSource : System.Web.UI.Page
{
    Authentication dllAuthentication = new Authentication();
     
    protected void Page_Load(object sender, EventArgs e)
    {
        dllAuthentication.isLogin();
        if (!IsPostBack)
        {
            
            bindMonthPlanGridView();
        }
    }


    /// <summary>
    /// 弹出小窗体事件
    /// </summary>
    /// <param name="msg"></param>
    public void ShowMessage(string msg)
    {
        EeekSoft.Web.PopupWin pop = new EeekSoft.Web.PopupWin();
        this.Controls.Add(pop);
        pop.Text = msg;
        pop.Message = msg;
        pop.Title = System.Configuration.ConfigurationManager.AppSettings["CompanyName"].ToString();
        pop.WindowScroll = true;
        pop.HideAfter = 99999999;
        pop.DockMode = EeekSoft.Web.PopupDocking.BottomLeft;
        pop.OffsetX = int.Parse(Session["_width"].ToString()) - 338;
        pop.ActionType = EeekSoft.Web.PopupAction.MessageWindow;
        pop.OffsetY = 1;
        pop.Width = 220;
        pop.Height = 170;
    }


    /// <summary>
    /// 
    /// </summary>
    void bindMonthPlanGridView()
    {
        //确定员工周计划来源于部门月周分解而来的员工周还是新员工月计划分解而来的员工周计划。
         
        int TypeId =Utility.HttpHelp.getParamsInt("TypeId");
        if (TypeId == 0)
        {
            this.GridViewWeek.Visible = false;
            //员工月计划分解而来。
            BLL.UserPlanMonth dllUserPlanMonth = new UserPlanMonth();
            BLL.UserMonthPlanDetailManager dllUserMonthPlanDetailManager = new UserMonthPlanDetailManager();
            object[] _value = new object[1];
            _value[0] = Utility.HttpHelp.getParamsInt("MonthPlanId");
            DataTable dt =  dllUserPlanMonth.get(UserPlanMonth.field.MonthPlanId.ToString(), _value);

            if (dt.Rows.Count > 0)
            { 
                this.gvlist.DataSource = dt;
                this.gvlist.DataBind(); 
                for (int i = 0; i < this.gvlist.Rows.Count; i++)
                {
                    wrapByComma(this.gvlist, i, 6);
                }

                //绑定员工月分解
                _value[0] = dt.Rows[0]["MonthPlanId"].ToString();
                DataTable dt_detial = dllUserMonthPlanDetailManager.get(UserMonthPlanDetailManager.field.Id.ToString(), _value);
                this.gvlistdetail.DataSource = dt_detial;
                this.gvlistdetail.DataBind();
            }
            else
            {
                //绑定员工月分解
                _value[0] = Utility.HttpHelp.getParamsString("MonthPlanId");
                DataTable dt_detial = dllUserMonthPlanDetailManager.get(UserMonthPlanDetailManager.field.Id.ToString(), _value);
                this.gvlistdetail.DataSource = dt_detial;
                this.gvlistdetail.DataBind();
                if (dt_detial.Rows.Count > 0)
                {
                    //绑定员工月计划
                    _value[0] = Convert.ToInt32(dt_detial.Rows[0]["MonthPlanId"]);
                    dt = dllUserPlanMonth.get(UserPlanMonth.field.MonthPlanId.ToString(), _value);
                    this.gvlist.DataSource = dt;
                    this.gvlist.DataBind();
                    for (int i = 0; i < this.gvlist.Rows.Count; i++)
                    {
                        wrapByComma(this.gvlist, i, 6);
                    }
                }
            }
        }
        else
        {
            //部门周
            this.gvlist.Visible = false;
            this.gvlistdetail.Visible = false;
            this.btnMonthDetail.Visible = false;
            object[] _value = new object[1];
            _value[0] = Utility.HttpHelp.getParamsInt("WeekPlanId");
            BLL.WeekPlanofManager dllWeekPlanofManager = new WeekPlanofManager();
            this.GridViewWeek.DataSource = dllWeekPlanofManager.get(WeekPlanofManager.field.WeekPlanId.ToString(), _value);
            this.GridViewWeek.DataBind();
           

            for (int i = 0; i < this.gvlist.Rows.Count; i++)
            {
                wrapByComma(this.gvlist, i, 6);
            }
        }
    }

    /// <summary>
    /// 根据逗号换行事件
    /// </summary>
    void wrapByComma(GridView _gridView, int _rowIndex, int _cells)
    {
        string _content = _gridView.Rows[_rowIndex].Cells[_cells].Text;
        _gridView.Rows[_rowIndex].Cells[_cells].Text = _content.Replace("&lt;br&gt;", "<br>");
        //_gridView.Rows[_rowIndex].Cells[_cells].Text = _content.Replace("&gt;", ">");
        _gridView.Rows[_rowIndex].Cells[_cells].Text = _gridView.Rows[_rowIndex].Cells[_cells].Text.Replace(",", "<br>");


    }

    /// <summary>
    /// 查看月分解
    /// </summary>
    /// <param name="sender"></param>
    /// <param name="e"></param>
    protected void btnMonthDetail_Click(object sender, EventArgs e)
    {
        string _url = "MonthPlanResolveDetail.aspx?_MonthPlanId=" + Utility.HttpHelp.getParamsInt("MonthPlanId");
        Page.RegisterStartupScript("windowsopen", "<script language=javascript>window.open('" + _url + "','MonthPlanResolveDetail','height=200,width=900,top=400,left=80,toolbar=no,menubar=no,scrollbars=yes,resizable=no,location=no,status=no');</script>");
    }
}
